import { Component, OnInit } from '@angular/core';
import { ActivatedRoute, ParamMap } from '@angular/router';
import { switchMap } from 'rxjs/operators';

const errorArr = [
  { img: './../../assets/img/403.svg', num: '403', message: '抱歉，你无权访问该页面' },
  { img: './../../assets/img/404.svg', num: '404', message: '抱歉，你访问的页面不存在' },
  { img: './../../assets/img/500.svg', num: '500', message: '抱歉，服务器出错了' },
];

@Component({
  selector: 'app-error',
  templateUrl: './error.component.html',
  styleUrls: ['./error.component.scss']
})

export class ErrorComponent implements OnInit {

  errMessage = errorArr[0];
  constructor(private route: ActivatedRoute) { }

  ngOnInit() {
    this.route.paramMap.subscribe(res => {
      switch (res.get('status')) {
        case '403':
          this.errMessage = errorArr[0];
          break;
        case '404':
          this.errMessage = errorArr[1];
          break;
        case '500':
          this.errMessage = errorArr[2];
          break;
      }
    });
  }

}
